package com.joinlabs.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.joinlabs.entity.Log;
import com.joinlabs.entity.Weibo;
import com.joinlabs.service.IUserService;
import com.joinlabs.service.IWeiboByTypeidService;
import com.joinlabs.service.IlogByTypenameService;

@Controller
@RequestMapping("/hotPage")
@SessionAttributes(names= {"user","weiboByTypeidList","logByTypeidList"})//声明要操作session域中的 多个 域对象的名字
public class HotClassifyPageAction {
	  @Resource
	   private IUserService userService;//用户
		@Resource
		private IWeiboByTypeidService weiboByTypeidService;//微博
		
		@Resource
		private IlogByTypenameService logByTypenameService;//日志
		//通过id查询微博信息
		@RequestMapping("/hotChild")
		public String hotChild(String typeid,ModelMap map) {
		    //System.out.println(typeid);
			System.out.println("日志答应赢哈哈哈那就坚决");
			if(typeid==null) {
				//查出全部微博
				List<Weibo> weiboByTypeidList = weiboByTypeidService.selectAllWeibo();
				//System.out.println(weiboByTypeidList.size());
				map.addAttribute("weiboByTypeidList", weiboByTypeidList);
				}else {
				//通过点击传入类别id查询微博
				List<Weibo> weiboByTypeidList = weiboByTypeidService.selectAllWeiboByTypeid(Long.parseLong(typeid));
				map.addAttribute("weiboByTypeidList",weiboByTypeidList);
				
				//通过点击传入类别id查询文章页面的
//				List<Dialog> DialogByTypeidList = dialogByTypeidService.selectAllDialogByTypeid(Long.parseLong(typeid));
//				map.addAttribute("DialogByTypeidList", DialogByTypeidList);
//				System.out.println(typeid);
//				
				}
			return "/hotPage/hotChild";
		}
		//查询文章信息
		@RequestMapping("/pageChild")
		public String pageChild(String typename,ModelMap map) {
			if(typename==null) {
				//查出全部微博
				List<Weibo> weiboByTypeidList = weiboByTypeidService.selectAllWeibo();
				//System.out.println(weiboByTypeidList.size());
				map.addAttribute("weiboByTypeidList", weiboByTypeidList);
				}else {
		
				//通过点击传入类别id查询文章页面的
				List<Log> logByTypeidList = logByTypenameService.selectAlllogByTypename(typename);
				map.addAttribute("logByTypeidList", logByTypeidList);
				System.out.println(typename);
				System.out.println("日志答应赢哈哈哈那就坚决"+logByTypeidList);
				}
			return "/hotPage/pageChild";
		}
}
